#include "myatomic.h"
#include "Lock.h"
static CLock sAtomicLocker;


unsigned int atomic_set(unsigned int *area, int val)
{
	sAtomicLocker.Lock();
    *area  = val;
    sAtomicLocker.Unlock();
    return *area;
}

unsigned int atomic_compare_set(unsigned int *area, int val)
{
	sAtomicLocker.Lock();
    if(val > *area)
        *area  = val;
    sAtomicLocker.Unlock();
    return *area;
}
unsigned int atomic_get(unsigned int *area)
{
    unsigned int rv = 0;
	sAtomicLocker.Lock();
    rv = *area;
    sAtomicLocker.Unlock();
    return rv;
}

bool atomic_compare(unsigned int *area, int val)
{
    int rv = 0;
    sAtomicLocker.Lock();
    if(val == *area)
        rv = 1;
    sAtomicLocker.Unlock();
    return rv;
}
